package com.soap.desensitize.posterity.string;

import com.soap.desensitize.encry.IDesensitization;
import com.soap.desensitize.exception.strategy.DecodeException;
import com.soap.desensitize.exception.strategy.EncodeException;
import com.soap.desensitize.posterity.AbstractPosterity;
import com.soap.desensitize.strategy.irreversible.PhoneStrtegy;

/**
 * @desc	手机号加密
 * @author 	gzy
 * @time	2022-04-21
 */
public class PhoneDesensitization extends AbstractPosterity<String> {
    /**
     * 默认使用手机号替换策略加密
     */
    private PhoneDesensitization(){
        super(PhoneStrtegy.getInstance());
    }
    private static PhoneDesensitization instance = null;
    /**
     * @desc 获得实例
     * @return
     */
    public static synchronized AbstractPosterity getInstance(){
        if(instance == null){
            instance = new PhoneDesensitization();
        }
        return instance;
    }
    /**
     * @desc 有参构造器
     * @param encry
     */
    public PhoneDesensitization(IDesensitization encry) {
        super(encry);
    }

    @Override
    public String encode(String data) throws EncodeException {
        return (String)encry.encode(data);
    }

    @Override
    public String decode(String data) throws DecodeException {
        return (String)encry.decode(data);
    }
}
